#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <qqmlengine.h>
#include <qqmlcontext.h>
#include <qqml.h>
#include <QtQuick/qquickitem.h>
#include <QtQuick/qquickview.h>
#include <QFontDatabase>

#include "serialporthelper.h"


int main(int argc, char *argv[])
{


    qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));

    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    //qmlRegisterType<SerialPort>("an.qt.mySerialPort",1,0,"SerialPort");
    qmlRegisterType<SerialPortHelper>("an.qt.mySerialPortHelper",1,0,"SerialPortHelper");
    //qRegisterMetaType<DeviceList>("DeviceList");
    qRegisterMetaType<QList<Device>>("QList<Device>");
    //qmlRegisterType<SerialPortHelper>("an.qt.mySerialPortHelper",1,0,"SerialPortHelper");

    //调试出系统字体列表
//    QFontDatabase database;
//    foreach (const QString &family, database.families(QFontDatabase::SimplifiedChinese))
//    {
//        qDebug()<<family;
//    }


    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("testModel", &station);
    engine.rootContext()->setContextProperty("portList", &portList);
    engine.rootContext()->setContextProperty("devicelist",&(devicelist));
    engine.rootContext()->setContextProperty("hostlist",&(hostlist));


    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}
